package com.zds.leetcode;

public class BST {
    private TreeNode root;

    public BST() {
        root = null;
    }

    // 插入方法
    public void insert(int value) {
        root = insertRec(root, value);
    }

    private TreeNode insertRec(TreeNode root, int value) {
        if (root == null) {
            root = new TreeNode(value);
            return root;
        }

        if (value < root.val) {
            root.left = insertRec(root.left, value);
        } else if (value > root.val) {
            root.right = insertRec(root.right, value);
        }

        return root;
    }

    // 查找方法
    public boolean search(int value) {
        return searchRec(root, value);
    }

    private boolean searchRec(TreeNode root, int value) {
        if (root == null) {
            return false;
        }

        if (value == root.val) {
            return true;
        }

        return value < root.val ? searchRec(root.left, value) : searchRec(root.right, value);
    }

    // 更多方法（如删除）可以在这里实现
}

